package com.cskaoyan.dbcp;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建日期: 2022/06/05 11:13
 *
 * @author ciggar
 */
public class DatasourceDemo {

    public static void main(String[] args) throws SQLException {

//        DataSource dataSource = new MyConnectionPoolV4();

        // 获取连接
        Connection connection = C3p0Utils.getConnection();

        System.out.println(connection.getClass());

        // 获取statement
        Statement statement = connection.createStatement();

        // 执行SQL语句
        ResultSet resultSet = statement.executeQuery("select * from cskaoyan");

        // 解析结果集
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String teacherName = resultSet.getString("teacher_name");
            String nickname = resultSet.getString("nickname");

            System.out.println("id:" + id + ", teacherName:" +teacherName + ",nickname:" +nickname);
        }

        // 释放资源
        resultSet.close();
        statement.close();
        connection.close();


    }
}
